package com.jinyi.custom.ui

import android.content.Intent
import android.graphics.Color
import android.view.View
import com.jinyi.custom.databinding.ActMainBinding
import com.jinyi.custom.ui.video.VideoPreviewActivity
import com.lib.base.base.BaseActivity
import com.lib.base.utils.DensityUtils
import com.lib.base.weight.CircleSeekBar

class MainActivity : BaseActivity() {

    lateinit var binding: ActMainBinding

    override fun getRootView(): View {
        binding = ActMainBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun initView() {
        setTextTitle("Home")
        setTitleBarVisibility(View.VISIBLE)
    }

    override fun initListener() {
        binding.btnShowLoading.setOnClickListener {
            showLoading()
        }
        binding.btnVideo.setOnClickListener {
            val intent = Intent(this,VideoPreviewActivity::class.java)
            startActivity(intent)
        }

        binding.circleSeekBar.setOnChangeListener(object : CircleSeekBar.OnChangeListener {
            override fun onStartTrackingTouch(isCanDrag: Boolean) {
            }

            override fun onProgressChanged(progress: Float, max: Float, fromUser: Boolean) {

            }

            override fun onStopTrackingTouch(isCanDrag: Boolean) {
            }

            override fun onSingleTapUp() {
            }

        })
    }

    override fun initData() {
        val minValue = 200000
        val maxValue = 400000
        val defaultValue = 200000
        binding.circleSeekBar.isShowPercentText = false
        binding.circleSeekBar.max = maxValue - minValue
        binding.circleSeekBar.progress = 0
        binding.circleSeekBar.labelText = "$minValue"
        binding.textAmount.text = "$minValue"

        val colors = intArrayOf(
            Color.parseColor("#ff48af6e"),
            Color.parseColor("#ff48af6e"),
            Color.parseColor("#ff1e492e"),
            Color.parseColor("#ff1e492e"),
        )
        val positions = floatArrayOf(0f, 0.35f, 0.6f, 1.0f)
        binding.circleSeekBar.setShader(colors,positions)

        binding.rulerView.setParam(
            DensityUtils.dp2px(10f),DensityUtils.dp2px(17f),DensityUtils.dp2px(17f),
            DensityUtils.dp2px(10f),DensityUtils.dp2px(9f), DensityUtils.dp2px(12f)
        )
        binding.rulerView.initViewParam(minValue.toFloat(), defaultValue.toFloat(), maxValue.toFloat(), 10 * 100)
        binding.rulerView.setValueChangeListener { value ->
            binding.textAmount.text ="${value.toInt()}"
            binding.circleSeekBar.labelText = "${value.toInt()}"
            binding.circleSeekBar.progress = (value - minValue).toInt()
        }
    }
}